const fs = require('fs');
const { json } = require('stream/consumers');

fs.access('../src/assets/data/sidebar-data.json', fs.constants.F_OK, (err) => {
    if (err) {
        return console.log('mini-library sidebar定义json文件不存在，未添加自定义sidebar')
    } else {
        fs.readFile('../src/assets/data/sidebar-data.json', 'utf-8', (err, data) => {
            if (err) {
                return console.log(err)
            }
            const objOrigin = JSON.parse(data);
            fs.readFile('../src/assets/data/sidebar-data-minilibrary.json', 'utf-8', (err, data) => {
                if (err) {
                    return console.log(err)
                }
                const objAdd = JSON.parse(data);
                objOrigin[0].children.push(...objAdd)
                fs.writeFile('../src/assets/data/sidebar-data.json', JSON.stringify(objOrigin), 'utf-8', () => {
                    console.log('写入文件成功')
                })
            })
        })
    }
})
